package com.infovane.action;

import com.infovane.base.BaseAction;
import com.infovane.model.TUser;
import com.infovane.service.AdminService;


public class AdminAction extends BaseAction{
	
	private AdminService adminService;
	
	
	public AdminService getAdminService() {
		return adminService;
	}


	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	/**
	 * 管理员登录
	 * */
	public String login(){
		String username=httpServletRequest.getParameter("username");
		String password=httpServletRequest.getParameter("password");
		if(username==null||username.equals("")){
			String warn="帐号不能为空!";
			httpServletRequest.setAttribute("WARN",warn);
			return ERROR;
		}else if(password==null||password.equals("")){
			String warn="密码不能为空!";
			httpServletRequest.setAttribute("WARN",warn);
			return ERROR;
		}else{
			TUser user=null;
			user=this.adminService.checkLogin(username, password);
			if(user!=null){
				httpServletRequest.getSession().setAttribute("ADMIN", user);
				httpServletRequest.getSession().setMaxInactiveInterval(1800);
				return SUCCESS;
			}else{
				String warn="帐号或密码错误!";
				httpServletRequest.setAttribute("WARN", warn);
			}
			
		}
		return ERROR;
	}
	
	/**
	 * 管理员退出登陆
	 * */
	public String logout(){
		httpServletRequest.getSession().invalidate();
		return SUCCESS;
	}

}
